package com.xinongbest.utils;

import java.sql.SQLException;

/**
 * @author lemonwan
 * 事务管理器
 */
public class TransactionManager {

//    private final static TransactionManager transactionManager = new TransactionManager();
//
//    private TransactionManager() {
//
//    }
//
//    public static TransactionManager getInstance() {
//        return  transactionManager;
//    }

    private ConnectionUtils connectionUtils;

    public void setConnectionUtils(ConnectionUtils connectionUtils) {
        this.connectionUtils = connectionUtils;
    }

    /**
     * 开启事务
     *
     * @throws SQLException
     */
    public void startTransaction() throws SQLException {
        // ConnectionUtils.getInstance().getConnect().setAutoCommit(false);
        connectionUtils.getConnect().setAutoCommit(false);
    }

    /**
     * 提交事务
     *
     * @throws SQLException
     */
    public void commit() throws SQLException {
        // ConnectionUtils.getInstance().getConnect().commit();
        connectionUtils.getConnect().commit();
    }

    /**
     * 回滚事务
     *
     * @throws SQLException
     */
    public void rollback() throws SQLException {
        // ConnectionUtils.getInstance().getConnect().rollback();
        connectionUtils.getConnect().rollback();
    }
}
